package com.qdxwx.data.service.member;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.utils.TKConvert;
import com.qdxwx.data.mapper.member.MemberSaleMapper;
import com.qdxwx.models.member.MemberSale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * MemberSale接口
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class MemberSaleServiceImpl implements MemberSaleService {

	@Autowired
	private MemberSaleMapper memberSaleMapper;

	/**
	 * 修改MemberSale(价格，开通天数)
	 *
	 * @param memberSale 要修改的MemberSale
	 */
	@Override
	public int update(MemberSale memberSale) {
		return memberSaleMapper.updateMemberSale(memberSale);
	}

	/**
	 * 根据id获取单个MemberSale对象
	 *
	 * @param id 要查询的id
	 * @return MemberSale
	 */
	@Override
	public MemberSale get(long id) {
		return memberSaleMapper.getMemberSaleById(id);
	}

	/**
	 * 添加会员商品
	 */
	@Override
	public int insert(MemberSale memberSale) {
		return memberSaleMapper.insertMemberSale(memberSale);
	}

	/**
	 * 删除会员商品
	 */
	@Override
	public int delete(String ids) {
		String[] arrIds = TKConvert.toStrArray(ids);
		if(arrIds.length < 1) return 0;
		return memberSaleMapper.deleteByIds(arrIds);
	}

	/**
	 * type获取MemberSale集合
	 * @param type
	 */
	@Override
	public List<MemberSale> getListByType(int type) {
		return memberSaleMapper.getMemberSaleByType(type);
	}


	@Override
	public List<MemberSale> getList(MemberSale memberSale, PageRequest page) {
		return memberSaleMapper.selectMemberSaleList(memberSale,page);
	}

	@Override
	public long count(MemberSale memberSale) {
		return memberSaleMapper.selectMemberSaleCount(memberSale);
	}

	@Override
	public int updateStatusByTypeId(int typeId, int status) {
		return memberSaleMapper.updateStatusByTypeId(typeId, status);
	}
}